package com.victor.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.victor.entity.PoiSubmit;
import com.victor.service.PoisubmitService;
import com.victor.utils.Msg;

@RestController
@RequestMapping("/poi")
public class PoiController {
	@Autowired
	private PoisubmitService poisubmitService;
	
	/**
	 * 查询poi列表
	 * @param page
	 * @param row
	 * @param aflag
	 * @return
	 */
	@RequestMapping("/getall")
	public Msg findAllPoi(int page,int row,String aflag) {
		if (aflag == null || aflag.isEmpty()) {
			return Msg.fail("入参错误");
		}
		PageInfo<PoiSubmit> pageInfo;
		if (aflag=="1" || aflag.equals("1")) {
			pageInfo = poisubmitService.selAdminCanLook(page,row);
		}else {
			pageInfo = poisubmitService.selAllCanLook(page,row);
		}
		return Msg.success().add("info", pageInfo);
	}
	/**
	 * 查询详情
	 * @param id
	 * @return
	 */
	@RequestMapping("/xiangqing")
	public Msg Xiangqing(Integer id) {
		if (id == null) {
			return Msg.fail("入参错误");
		}
		PoiSubmit poiSubmit = poisubmitService.selById(id);
		return Msg.success().add("poiSubmit", poiSubmit);
	}
	/**
	 * 修改状态
	 * @param poiSubmit
	 * @return
	 */
	@RequestMapping("/update")
	public Msg updateFlag(PoiSubmit poiSubmit) {
		if (poiSubmit.getId()== null || poiSubmit.getFlag() == null || poiSubmit.getFlag().isEmpty()) {
			return Msg.fail("入参失败");
		}
		if (poiSubmit.getFlag()=="1" || poiSubmit.getFlag().equals("1")) {
			poiSubmit.setFlag("1");
			boolean b = poisubmitService.update(poiSubmit);
			if (!b) {
				return Msg.fail("修改poi状态失败");
			}
		}
		if (poiSubmit.getFlag()=="2" || poiSubmit.getFlag().equals("2")) {
			poiSubmit.setFlag("2");
			boolean b = poisubmitService.update(poiSubmit);
			if (!b) {
				return Msg.fail("修改poi状态失败");
			}
		}
		if (poiSubmit.getFlag()=="3" || poiSubmit.getFlag().equals("3")) {
			poiSubmit.setFlag("3");
			boolean b = poisubmitService.update(poiSubmit);
			if (!b) {
				return Msg.fail("修改poi状态失败");
			}
		}
		if (poiSubmit.getFlag()=="4" || poiSubmit.getFlag().equals("4")) {
			poiSubmit.setFlag("4");
			boolean b = poisubmitService.update(poiSubmit);
			if (!b) {
				return Msg.fail("修改poi状态失败");
			}
		}
		return Msg.success();
		
	}

}
